#ifndef MM_SOURCE_H
#define MM_SOURCE_H

#include <QObject>
#include <QSharedPointer>
#include <QDateTime>
#include <QVariant>
#include <QUrl>
#include "Application.h"

namespace MessagingMenu
{
class Application;
class Message;
class Source : public QObject
{
    Q_OBJECT
    Q_ENUMS(Type)

public:
    Source(Application *parent, const QString &id, const QString &label, const QUrl &icon);

    enum Type {
        TIME,
        COUNT,
        STRING
    };

    QString id() const;
    QString label() const;
    QUrl icon() const;

    bool persistent() const;
    bool hasCount() const;
    bool hasTime() const;
    bool hasString() const;

    Type type() const;
    qint32 count() const;
    QDateTime time() const;
    QString srcString() const;
    bool requiresAttention() const;
    int position() const;
    // A call to create() will add this source to the messaging menu
    void create();
    // call this if we got removed from the messaging menu
    void removed();
    static void messageActivated(MessagingMenuMessage *message, const char *actionId, GVariant *param, gpointer *instance);
    Message *createMessage(const QString &msgId, const QString &title, const QString &subtitle, const QString &body, const QDateTime &time, const QUrl &icon);

    MessagingMenuApp *getApp();


Q_SIGNALS:
    void persistentChanged(bool persistent);
    void typeChanged(Type type);
    void idChanged(QString id);
    void labelChanged(QString label);
    void iconChanged();
    void countChanged(qint32 count);
    void timeChanged(QDateTime time);
    void srcStringChanged(QString sourceString);
    void positionChanged(int position);
    void requiresAttentionChanged(bool requiresAttention);
    // emitted when a child MessagingMenuMessage is activated
    void menuMessageActivated(const QString &msgId);

public Q_SLOTS:
    void setPersistent(const bool persistent);
    void setType(const Type type);
    void setId(const QString &id);
    void setIcon(const QUrl &icon);
    void setCount(const qint32 &count);
    void setTime(const QDateTime &time);
    void setSrcString(const QString &sourceString);
    void setPosition(const int &position);
    void setRequiresAttention(const bool requiresAttention);

    // These functions interact with messaging menu
    void setSourceCount();
    void setSourceTime();
    void setSourceString();
    void setSourceLabel();
    void setSourceIcon();
    void setSourceRequiresAttention();

private:
    Application *m_app;
    QHash<QString, QSharedPointer<Message> > m_messages;
    bool m_isPersistent;
    Type m_type;
    QVariant m_sourceValue;
    QString m_id;
    QString m_label;
    QUrl m_icon;
    qint32 m_count;
    QDateTime m_time;
    QString m_sourceString;
    int m_position;
    bool m_requiresAttention;
    bool m_created;
};
}
#endif // SOURCE_H
